package net.crashtoot.picasa.web.rest;

import java.util.List;

import net.crashtoot.picasa.core.model.Account;
import net.crashtoot.picasa.core.model.Photo;
import net.crashtoot.picasa.core.service.AccountService;
import net.crashtoot.picasa.core.service.PhotoService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/photo")
public class PhotoController {
    private static final Log log = LogFactory.getLog(PhotoController.class);

    @Autowired
    private AccountService accountService;

    @Autowired
    private PhotoService photoService;

    /**
     * @param userId : username
     * @param albumId : id de l'album
     * @return les photos de l'album
     * @throws Exception
     */
    @RequestMapping(value = "/{userId:.*}/{albumId:.*}")
    public List<Photo> getPhotos(@PathVariable String userId, @PathVariable String albumId) throws Exception {
        Account account = accountService.getAccountByUserName(userId);
        if (account == null) {
            return null;
        }
        List<Photo> photos = photoService.getPhotos(albumId, account);

        log.debug(photos.size() + " photos dans l'album : " + albumId);

        return photos;
    }
}
